/**
 * $Date: 2013-09-18 22:09:07 +0200 (Wed, 18 Sep 2013) $
 * $Revision: 5 $
 * $Author: erik.bartos@gmail.com $
 * $HeadURL: https://form-factor.googlecode.com/svn/trunk/Nucleons/modules/PlotGraph.cpp $
 * $Id: PlotGraph.cpp 5 2013-09-18 20:09:07Z erik.bartos@gmail.com $
 *
 * @file
 * @brief	Preview of functions and data.
 */

#include "PlotGraph.h"

PlotGraph::PlotGraph () {
	// To set white color for graph
    TStyle *plain = new TStyle("Plain","Plain Style(no colors/fill areas)");
	plain->SetCanvasBorderMode(0);
    plain->SetPadBorderMode(0);
    plain->SetPadColor(0);
    plain->SetCanvasColor(0);
    plain->SetTitleColor(1);
    plain->SetStatColor(0);
	plain->SetTitleBorderSize(0);
	//gROOT->SetStyle(plain);
	plain->cd();
	title = "How does function look like?";
}

/// One graph with defined title
void PlotGraph::view (Int_t num, Double_t axisX[], Double_t axisY[]) {

    TCanvas *c1 = new TCanvas ("c1", "Graph", 10, 10, 600, 500);
    c1->SetLogy(); // logarithmic scale

    TGraph *gr = new TGraph (num, axisX, axisY);

	gr->Draw("AL");
    gr->SetTitle(title);
    gr->GetXaxis()->CenterTitle();
    gr->GetYaxis()->CenterTitle();
}

/// One graph with optional title
void PlotGraph::view (Int_t num, Double_t axisX[], Double_t axisY[], Char_t const* title) {

    TCanvas *c1 = new TCanvas ("c1", "Graph", 10, 10, 600, 500);
	c1->SetLogy();
    TGraph *gr = new TGraph (num, axisX, axisY);
	
    gr->Draw("AL");
    gr->GetXaxis()->CenterTitle();
    gr->GetYaxis()->CenterTitle();

	gr->GetXaxis()->SetTitle("t [GeV^{2}]");
	gr->GetYaxis()->SetTitle(title);
	//gr->SetTitle(title);
	gr->SetTitle();
}

/// Two separate graphs
void PlotGraph::view2 (Int_t num, Double_t axisX[], Double_t axisY1[], Double_t axisY2[]) {

	TCanvas *c2 = new TCanvas ("c2", "Graph", 10, 10, 900, 500);
    c2->SetLogy(); // logarithmic scale
	c2->Divide(2,1);

	c2->cd(1);
	gPad->SetLogy();
    TGraph *gr1 = new TGraph (num, axisX, axisY1);
	gr1->SetTitle("Graph 1");
	gr1->Draw("AL");
	
	c2->cd(2);
	gPad->SetLogy();
	TGraph *gr2 = new TGraph (num, axisX, axisY2);
	gr2->SetTitle("Graph 2");
	gr2->Draw("AL");
}

/// View data
void PlotGraph::viewData (Int_t num, Double_t axisX[], Double_t axisY[]) {

	TCanvas *c3 = new TCanvas ("c3", "Data", 10, 10, 500, 500);
    //c3->SetLogy(); // logarithmic scale
	
	TGraph *gr3 = new TGraph (num, axisX, axisY);
	gr3->Draw("AP");
	gr3->SetMarkerStyle(21);
	gr3->SetMarkerSize(.5);
}

/// One graph with data points
void PlotGraph::viewPlusData (Int_t num, Double_t axisX[], Double_t axisY[], Int_t numD, Double_t axisXD[], Double_t axisYD[]) {

	TCanvas *c4 = new TCanvas ("c4", "Graph", 1400, 30, 500, 500);
    //c4->SetLogy(); // logarithmic scale

    TGraph *gr4 = new TGraph (num, axisX, axisY);
	gr4->Draw("AL");
    //gr4->SetTitle("Function with experimental points");
    gr4->SetTitle("");
    gr4->GetXaxis()->CenterTitle();
    gr4->GetYaxis()->CenterTitle();

    TGraph *gr5 = new TGraph (numD, axisXD, axisYD);
	gr5->Draw("P");
	gr5->SetMarkerStyle(21);
	gr5->SetMarkerSize(.5);
}

/// One graph with data points and title
void PlotGraph::viewPlusData (Int_t num, Double_t axisX[], Double_t axisY[], Int_t numD, Double_t axisXD[], Double_t axisYD[], Char_t const* title) {

	TCanvas *c4 = new TCanvas ("c4", "Graph", 10, 10, 600, 500);
	c4->SetLogy(); // logarithmic scale

	TGraph *gr4 = new TGraph (num, axisX, axisY);
	gr4->Draw("AL");
    //gr4->SetTitle("Function with experimental points");
    gr4->SetTitle(title);
    gr4->GetXaxis()->CenterTitle();
    gr4->GetYaxis()->CenterTitle();
	//gr4->GetXaxis()->SetLimits(0.5,0.);
	//tl = new TLatex();
	//tl->DrawLatex(0.22,0.15,"#sqrt{s} = 500(GeV)");

    TGraph *gr5 = new TGraph (numD, axisXD, axisYD);
	gr5->Draw("P");
	gr5->SetMarkerStyle(21);
	gr5->SetMarkerSize(.5);
}

/// One graph with data points and errors
void PlotGraph::viewPlusDataE (Int_t num, Double_t axisX[], Double_t axisY[], Int_t numD, Double_t axisXD[], Double_t axisYD[], Double_t axisXED[], Double_t axisYED[], const Char_t* title) {

	TCanvas *c5 = new TCanvas ("c5", "Graph", 620, 10, 600, 500);
    c5->SetLogy(); // logarithmic scale

    TGraph *gr6 = new TGraph (num, axisX, axisY);
	gr6->Draw("AL");
	gr6->GetXaxis()->SetTitle("t [GeV^{2}]");
	gr6->GetYaxis()->SetTitle(title);
    //gr6->SetTitle(title);
    gr6->SetTitle();
    gr6->GetXaxis()->CenterTitle();
    gr6->GetYaxis()->CenterTitle();
	gr6->SetMaximum(2.);

    TGraphErrors *gr7 = new TGraphErrors (numD, axisXD, axisYD, axisXED, axisYED);
	gr7->Draw("P");
	gr7->SetMarkerStyle(21);
	gr7->SetMarkerSize(.7);
	gr7->SetMarkerColor(2);
}


/// One graph with data points and asymmetric errors
void PlotGraph::viewPlusDataAE (Int_t num, Double_t axisX[], Double_t axisY[], Int_t numD, Double_t axisXD[], Double_t axisYD[], Double_t axisXExl[], Double_t axisXExh[], Double_t axisYEyl[], Double_t axisYEyh[], Char_t const* title) {

	TCanvas *c6 = new TCanvas ("c6","Graph", 620, 10, 600, 500);
    c6->SetLogy(); // logarithmic scale

	TMultiGraph *mg = new TMultiGraph();

    TGraph *grm1 = new TGraph (num, axisX, axisY);
	TGraphAsymmErrors *grm2 = new TGraphAsymmErrors (numD, axisXD, axisYD, axisXExl, axisXExh, axisYEyl, axisYEyh);
	grm2->SetMarkerStyle(21);
	grm2->SetMarkerSize(.7);
	grm2->SetMarkerColor(2);

	mg->Add(grm1,"L");
	mg->Add(grm2,"P");
	mg->Draw("A");

	mg->GetXaxis()->SetTitle("t [GeV^{2}]");
	mg->GetYaxis()->SetTitle(title);
    mg->GetXaxis()->CenterTitle();
    mg->GetYaxis()->CenterTitle();

	// Change the axis limits
	gPad->Modified();
	mg->GetXaxis()->SetLimits(-7.5,15.);
	mg->SetMinimum(0.01);
	mg->SetMaximum(10000.);

	TLegend *leg = new TLegend (.5,.7,.87,.87);
	leg->SetFillColor(kWhite);
 	leg->AddEntry(grm1,title,"l");
	leg->AddEntry(grm2,"World data with errors","ep");
	leg->SetTextSize(0.03);
	leg->Draw();
	
	c6->Print("viewPlusDataAE.eps");
}

/// Two graphs in one canvas
void PlotGraph::viewPrint (Int_t num, Double_t axisX[], Double_t axisY1[], Double_t axisY2[]) {

	TCanvas *c7 = new TCanvas ("c7", "Graph", 10, 10, 500, 500);
//    c7->SetLogy(); // logarithmic scale
	TGraph *gr8 = new TGraph (num, axisX, axisY1);
	gr8->SetLineStyle(kDashed);
	gr8->Draw("AL");
	
	TGraph *gr9 = new TGraph (num, axisX, axisY2);
	gr9->Draw("L");
  
	gr9->GetXaxis()->SetTitle("x");
	gr9->GetYaxis()->SetTitle("y");
	gr9->SetTitle("T");
	gr9->GetXaxis()->CenterTitle();
	gr9->GetYaxis()->CenterTitle();
	//gr9->SetMaximum(1);
	gr9->GetXaxis()->SetLimits(0.,1.00001);

	TLegend *leg = new TLegend (.7,.77,.87,.87);
	leg->SetFillColor(kWhite);
 	leg->AddEntry(gr8,"curve I.","l");
	leg->AddEntry(gr9,"curve II.","l");
	leg->Draw();
}

/// Four separate graphs
void PlotGraph::view4 (Int_t num, Double_t axisX[], Double_t axisY1[], Double_t axisY2[], Double_t axisY3[], Double_t axisY4[]) {

	TCanvas *c8 = new TCanvas ("c8", "Graph", 2000, 30, 900, 500);
	c8->Divide(2,2);

	c8->cd(1);
    gPad->SetLogy();
	TGraph *gr10 = new TGraph (num, axisX, axisY1);
	gr10->SetTitle("Graph 1");
	gr10->Draw("AL");

	c8->cd(2);
    gPad->SetLogy();	
    TGraph *gr11 = new TGraph (num, axisX, axisY2);
	gr11->SetTitle("Graph 2");
	gr11->Draw("AL");
	
	c8->cd(3);
    gPad->SetLogy();
	TGraph *gr12 = new TGraph (num, axisX, axisY3);
	gr12->SetTitle("Graph 3");
	gr12->Draw("AL");

	c8->cd(4);
	gPad->SetLogy();
	TGraph *gr13 = new TGraph (num, axisX, axisY4);
	gr13->SetTitle("Graph 4");
	gr13->Draw("AL");
}

/// Four separate graphs with experimental data
void PlotGraph::view4Exp (Int_t num, Double_t axisX[], Double_t axisY1[], Double_t axisY2[], Double_t axisY3[], Double_t axisY4[], Int_t num1, Double_t axisEX1[], Double_t axisEY1[], Int_t num2, Double_t axisEX2[], Double_t axisEY2[], Int_t num3, Double_t axisEX3[], Double_t axisEY3[], Int_t num4, Double_t axisEX4[], Double_t axisEY4[]) {

	TCanvas *c9 = new TCanvas ("c9", "Graph", 150, 30, 1200, 800);
	c9->Divide(2,2);

	c9->cd(1);
    gPad->SetLogy();
	TGraph *gr20 = new TGraph (num, axisX, axisY1);
	gr20->SetTitle("G_E^p");
	gr20->Draw("AL");
    TGraph *gr21 = new TGraph (num1, axisEX1, axisEY1);
	gr21->Draw("P");
	gr21->SetMarkerStyle(21);
	gr21->SetMarkerSize(.5);

	c9->cd(2);
    gPad->SetLogy();	
    TGraph *gr22 = new TGraph (num, axisX, axisY2);
	gr22->SetTitle("G_M^p");
	gr22->Draw("AL");
    TGraph *gr23 = new TGraph (num2, axisEX2, axisEY2);
	gr23->Draw("P");
	gr23->SetMarkerStyle(21);
	gr23->SetMarkerSize(.5);
	
	c9->cd(3);
    gPad->SetLogy();
	TGraph *gr24 = new TGraph (num, axisX, axisY3);
	gr24->SetTitle("G_E^n");
	gr24->Draw("AL");
    TGraph *gr25 = new TGraph (num3, axisEX3, axisEY3);
	gr25->Draw("P");
	gr25->SetMarkerStyle(21);
	gr25->SetMarkerSize(.5);

	c9->cd(4);
	gPad->SetLogy();
	TGraph *gr26 = new TGraph (num, axisX, axisY4);
	gr26->SetTitle("G_M^n");
	gr26->Draw("AL");
    TGraph *gr27 = new TGraph (num4, axisEX4, axisEY4);
	gr27->Draw("P");
	gr27->SetMarkerStyle(21);
	gr27->SetMarkerSize(.5);		
}
